//
//  JHAssetsCollectionCell.m
//  JHAssetsPhotoPickerViewController
//
//  Created by admin on 15/11/16.
//  Copyright © 2015年 mohe. All rights reserved.
//

#import "JHAssetsCollectionCell.h"

@implementation JHAssetsCollectionCell
{
    CALayer *layerSpaceA;
    CALayer *layerA;
    CALayer *layerSpaceB;
    CALayer *layerB;
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        [self initSubLayers];
        [self initSubViews];
        [self setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
    }
    return self;
}

- (void)initSubViews
{
    [self setBackgroundColor:[UIColor whiteColor]];
    self.coverImageView = [[UIImageView alloc]init];
    [self.coverImageView setBackgroundColor:[UIColor whiteColor]];
    
    self.titleView = [[UILabel alloc]init];
    [self.titleView setFont:[UIFont systemFontOfSize:17]];
    
    self.numberLabel = [[UILabel alloc]init];
    [self.numberLabel setFont:[UIFont systemFontOfSize:15]];
    
    [self.contentView addSubview:self.coverImageView];
    [self.contentView addSubview:self.titleView];
    [self.contentView addSubview:self.numberLabel];

}

- (void)initSubLayers
{
    layerSpaceA = [CALayer layer];
    [layerSpaceA setBackgroundColor:[UIColor whiteColor].CGColor];
    layerA = [CALayer layer];
    [layerA setBackgroundColor:[UIColor grayColor].CGColor];
    layerSpaceB = [CALayer layer];
    [layerSpaceB setBackgroundColor:[UIColor whiteColor].CGColor];
    layerB = [CALayer layer];
    [layerB setBackgroundColor:[UIColor grayColor].CGColor];
    [layerB setShadowColor:[UIColor lightGrayColor].CGColor];
    [layerB setShadowOffset:CGSizeMake(1, 1)];
    [layerB setShadowRadius:1];
    [layerB setShadowOpacity:1];
    [self.contentView.layer addSublayer:layerB];
    [self.contentView.layer addSublayer:layerSpaceB];
    [self.contentView.layer addSublayer:layerA];
    [self.contentView.layer addSublayer:layerSpaceA];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    [self.coverImageView setFrame:CGRectMake(16, 0, kGroupCellHeight-16, kGroupCellHeight-16)];
    [self.coverImageView setCenter:CGPointMake(self.coverImageView.center.x, (kGroupCellHeight-6)/2.0f)];
    CGFloat x = CGRectGetMaxX(self.coverImageView.frame)+20;
    [layerSpaceA setFrame:CGRectMake(self.coverImageView.frame.origin.x+1, self.coverImageView.frame.origin.y+1, self.coverImageView.frame.size.width, self.coverImageView.frame.size.height)];
    [layerA setFrame:CGRectMake(self.coverImageView.frame.origin.x+2, self.coverImageView.frame.origin.y+2, self.coverImageView.frame.size.width, self.coverImageView.frame.size.height)];
    [layerSpaceB setFrame:CGRectMake(self.coverImageView.frame.origin.x+3, self.coverImageView.frame.origin.y+3, self.coverImageView.frame.size.width, self.coverImageView.frame.size.height)];
    [layerB setFrame:CGRectMake(self.coverImageView.frame.origin.x+4, self.coverImageView.frame.origin.y+4, self.coverImageView.frame.size.width, self.coverImageView.frame.size.height)];
    CGFloat textHeight = 22.0f;
    [self.titleView setFrame:CGRectMake(x, kGroupCellHeight/2.0f-textHeight, self.frame.size.width-x-textHeight, textHeight)];
    [self.numberLabel setFrame:CGRectMake(x, kGroupCellHeight/2.0f, self.frame.size.width-x-textHeight, textHeight)];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
